<?php
    require('inc/header.php');
    if(TheUser::isLoggedIn()) {
        header("Location: index.php");
    }
    
    if(isset($_POST['login']) && isset($_POST['password'])) {
        if(!TheUser::logIn($_POST['login'], $_POST['password'])) {
            $error = Error::instance();
            $error->add("Błędne dane logowania!");
        }
        else {
            header("Location: index.php");
        }
    }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="pl">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
		<meta name="Content-Language" content="pl">
                <link rel="stylesheet" href="stylesheet.css" type="text/css">
		<title>Logowanie do WTCS</title>
                <style>
                    html {
                        border: none !important;
                        box-shadow: none !important;
                    }
                </style>
	</head>
	<body>
	<div style="width: 800px; margin: 100px auto;">
		<div style="margin: auto; height: 200px; width: 300px;">
		<form action="login.php" method="post">
			<fieldset style="text-align:right; padding-right: 50px; padding-top: 10px">
			<legend style="padding: 0 5px;">Logowanie do WTCS</legend>
				Login: <input type="text" name="login" style="margin-left: 5px;" /><br />
				Hasło: <input type="password" name="password" style="margin-left: 5px;" /><br />
				<?php
                                    $errors = Error::instance();
                                    if($errors->count()) {
                                        foreach($errors->get() as $key => $errorTxt) {
                                            echo '<span style="display:inline-block; margin-top: 5px;" class="error">' . $errorTxt . '</span>';
                                        }
                                    }
                                ?>
				<input type="submit" value="Zaloguj" style="margin-top: 10px;" /><br />
			</fieldset>
		</form>		
		</div>
	</div>
	</body>
</html>